package com.example.springioc.controller;


import com.example.springioc.config.UserConfiguration;
import com.example.springioc.dao.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;


// 使用Controller注解将UserController存入spring中
@Controller
public class UserController {


    public void sayHello() {
        System.out.println("Hello World");
    }

    /*
           @Autowired注解实现依赖注入的三种方式
           1. 属性注入
           2. 构造方法注入
           3. setter方法注入
     */
    // 属性注入
    @Autowired
    private UserConfiguration userConfiguration;

    public void say() {
        userConfiguration.fun();
        System.out.println("hello,userController");

    }



    private UserConfiguration userConfiguration1;
    //  构造方法注入
    // 如果类只有⼀个构造⽅法，那么 @Autowired 注解可以省略
    @Autowired
    public UserController(UserConfiguration userConfiguration1) {
        this.userConfiguration1 = userConfiguration1;
    }


    public UserController() {
    }

    public void say1() {
        userConfiguration1.fun();
        System.out.println("hello,userController1");
    }



    private UserConfiguration userConfiguration2;

    @Autowired
    // Setter 注⼊
    public void setUserConfiguration2(UserConfiguration userConfiguration2) {
        this.userConfiguration2 = userConfiguration2;
    }

    public void say2() {
        userConfiguration2.fun();
        System.out.println("hello,userController2");
    }

}
